home *** CD-ROM | disk | FTP | other *** search
/ Digital Information Mana…ntial Guide to Multimedia / Digital Information Management - An Essential Guide to Multimedia.iso / Audacity / Nyquist / misc.lsp < prev    next >
Lisp/Scheme  |  2006-05-16  |  3KB  |  93 lines

  1. ;## misc.lsp -- a collection of useful support functions
  2.  
  3. ; enable or disable breaks
  4. (defun bkon () (setq *breakenable* T))
  5. (defun bkoff () (setq *breakenable* NIL))
  6.  
  7. (bkon)
  8.  
  9. ;; (grindef 'name) - pretty print a function
  10. ;;
  11. (defun grindef (e) (pprint (get-lambda-expression (symbol-function e))))
  12.  
  13. ;; (incf <place>), (decf <place>) - add/sub 1 to/from variable
  14. ;;
  15. (defmacro incf (symbol) `(setf ,symbol (1+ ,symbol)))
  16. (defmacro decf (symbol) `(setf ,symbol (1- ,symbol)))
  17.  
  18.  
  19. ;; (push val <place>) - cons val to list
  20. ;;
  21. (defmacro push (val lis) `(setf ,lis (cons ,val ,lis)))
  22. (defmacro pop (lis) `(setf ,lis (cdr ,lis)))
  23.  
  24. ;; include this to use RBD's XLISP profiling hooks
  25. ;;(load "/afs/andrew/usr/rbd/lib/xlisp/profile.lsp")
  26.  
  27. ;(cond ((boundp 'application-file-name)
  28. ;       (load application-file-name)))
  29.  
  30.  
  31. (defun get-input-file-name ()
  32.   (let (fname)
  33.     (format t "Input file name: ")
  34.     (setf fname (read-line))
  35.     (cond ((equal fname "") (get-input-file-name))
  36.           (t fname))))
  37.  
  38.  
  39. (defun open-output-file ()
  40.   (let (fname)
  41.     (format t "Output file name: ")
  42.     (setf fname (read-line))
  43.     (cond ((equal fname "") t)
  44.           (t (open fname :direction :output)))))
  45.  
  46.  
  47. (defmacro while (cond &rest stmts)
  48.   `(prog () loop (if ,cond () (return)) ,@stmts (go loop)))
  49.  
  50. (defmacro when (test action)
  51.         (list 'cond (list test action)))
  52.  
  53. ; when parens/quotes don't match, try this
  54. (defun file-sexprs ()
  55.   (let ((fin (open (get-input-file-name)))
  56.         inp)
  57.     (while (setf inp (read fin)) (print inp))))
  58.  
  59. ;; get path for currently loading file (if any)
  60. ;;
  61. (defun current-path ()
  62.   (let (fullpath n)
  63.     (setf n -1)
  64.     (cond (*loadingfiles*
  65.            (setf fullpath (car *loadingfiles*))
  66.            (dotimes (i (length fullpath))
  67.              (cond ((equal (char fullpath i) *file-separator*)
  68.                     (setf n i))))
  69.            (setf fullpath (subseq fullpath 0 (1+ n)))
  70.            ;; if this is a Mac, use ':' in place of empty path
  71.            (cond ((and (equal fullpath "") 
  72.                        (equal *file-separator* #\:))
  73.                   (setf fullpath ":")))
  74.            fullpath)
  75.           (t nil))))
  76.           
  77. ;; real-random -- pick a random real from a range
  78. ;;
  79. (defun real-random (from to)
  80.   (cond ((= from to) from)
  81.           (t
  82.          (+ from
  83.            (* (random 10000)
  84.               0.0001
  85.               (- to from))))))
  86.  
  87. ;; power -- raise a number to some power x^y
  88. ;;
  89. (defun power (x y)
  90.   (exp (* (log (float x)) y)))
  91.   
  92.